let capturedToken = null;

// 监听所有网络请求
chrome.webRequest.onBeforeSendHeaders.addListener(
  (details) => {
    const headers = details.requestHeaders;
    const authHeader = headers.find(
      h => h.name.toLowerCase() === "token" // 可修改为其他头如 "x-auth-token"
    );

    if (authHeader) {
      capturedToken = authHeader.value;
      chrome.storage.local.set({ token: capturedToken });
    }
  },
  { urls: ["http://172.25.142.67/*", "https://testhrssc.mychery.com/*"] },
  ["requestHeaders", "extraHeaders"]
);
